function istd = fsb_calculate_std(idat)

% FSB: Calculate image std while ignoring parts where the image is zero
%
% EXAMPLE:
% istd = f_calculate_std(idat)
%
% INPUT:
% idat:         4-D image information
%
% OUTPUT:
% istd:         Standard deviation of the 4-D dataset in the 4th dimension
%
% CALLED BY:
% fsb_remove_outliers.m
%
% Copyright 2010 MPI for Biological Cybernetics
% Author: Steffen Stoewer
% License:GNU GPL, no express or implied warranties
% 
%$ Revision 1.0
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

idat = single(idat);
idat(idat==0) = NaN;
istd = nanstd(idat,0,4);% calculate brain SD

end
